home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / p4 / p4-1_2c.lha / p4-1.2c / lib / p4_procgroup.c < prev    next >
C/C++ Source or Header  |  1993-05-24  |  3KB  |  117 lines

  1. #include "p4.h"
  2. #include "p4_sys.h"
  3.  
  4. #ifdef TCMP
  5. extern struct tc_globmem *tcglob;
  6. #endif
  7.  
  8. struct p4_procgroup *p4_alloc_procgroup()
  9. {
  10.     struct p4_procgroup *pg;
  11.  
  12.     if (!(pg = (struct p4_procgroup *) p4_malloc(sizeof(struct p4_procgroup))))
  13.     p4_error("p4_alloc_procgroup: p4_malloc failed",
  14.          sizeof(struct p4_procgroup));
  15.  
  16.     p4_dprintfl(90, "p4_alloc_procgroup: allocing %d bytes\n",
  17.         sizeof(struct p4_procgroup));
  18.  
  19.     pg->num_entries = 0;
  20.     return (pg);
  21. }
  22.  
  23. struct p4_procgroup *read_procgroup()
  24. {
  25.     FILE *fp;
  26.     char buf[1024], *s;
  27.     struct p4_procgroup_entry *pe;
  28.     int i, group_id, pt_index, n;
  29.     struct p4_procgroup *pg;
  30.     struct passwd *pwent;
  31.     char *logname; 
  32.  
  33.  
  34.     p4_dprintfl(90,"entering read_procgroup\n");
  35.     pg = p4_alloc_procgroup();
  36.  
  37. #   if defined(CM5)  ||  defined(NCUBE)
  38.     logname = '\0';
  39. #   else
  40.     logname = (char *) getlogin();
  41. #   endif
  42.  
  43.     if ((fp = fopen(procgroup_file, "r")) == NULL)
  44.     p4_error("open error on procgroup file",NULL);
  45.  
  46.     pe = pg->entries;
  47.  
  48.     while (fgets(buf, sizeof(buf), fp) != NULL)
  49.     {
  50.     for (s = buf; isspace(*s); s++)
  51.         ;
  52.  
  53.     if (*s == '#' || *s == '\0')    /* Ignore comments & blanks */
  54.         continue;
  55.  
  56.     n = sscanf(buf, "%s %d %s %s",
  57.            pe->host_name,
  58.            &pe->numslaves_in_group,
  59.            pe->slave_full_pathname,
  60.            pe->username);
  61.  
  62.     if (n == 3)
  63.     {
  64.         if (logname != NULL && logname[0] != '\0')
  65.         strcpy(pe->username, logname);
  66.         else
  67.         {
  68. #               if defined(CM5)  ||  defined(NCUBE)
  69.                 strcpy(pe->username, "cube-user");
  70. #               else
  71.         if ((pwent = getpwuid(getuid())) == NULL)
  72.             p4_error("create_procgroup: getpwuid failed", 0);
  73.         strcpy(pe->username, pwent->pw_name);
  74. #               endif
  75.         }
  76.     }
  77.     pe++;
  78.     pg->num_entries++;
  79.     if (pg->num_entries > P4_MAX_PROCGROUP_ENTRIES)
  80.         p4_error("read procgroup: exceeded max # of procs",
  81.              P4_MAX_PROCGROUP_ENTRIES);
  82.     }
  83.  
  84.     dump_procgroup(pg,50);
  85.     return (pg);
  86. }                /* read_procgroup */
  87.  
  88.  
  89. int install_in_proctable(group_id,port,unix_id,host_name,
  90.              slv_idx,machine_type,switch_port)
  91. int group_id;
  92. int port;
  93. int unix_id;
  94. char host_name[64];
  95. int slv_idx;
  96. char machine_type[];
  97. int switch_port;
  98. {
  99.     struct p4_global_data *g;
  100.     struct proc_info *pi;
  101.  
  102.     g = p4_global;
  103.     pi = &g->proctable[g->num_installed];
  104.     pi->group_id = group_id;
  105.     pi->port = port;
  106.     pi->unix_id = unix_id;
  107.     strcpy(pi->host_name, host_name);
  108.     strcpy(pi->machine_type,machine_type);
  109.     pi->slave_idx = slv_idx;
  110.     pi->switch_port = switch_port;
  111.     g->num_installed++;
  112.     p4_dprintfl(50, "installed in proctable num=%d port=%d host=%s unix=%d slav=%d grp=%d swport=%d\n",
  113.         g->num_installed, port, host_name, unix_id, slv_idx, pi->group_id,pi->switch_port);
  114.     return (g->num_installed - 1);
  115. }
  116.  
  117.